<template>
	<view class="order-success">
		<!-- #ifdef APP-PLUS -->
		<top-set backgroundColor="#3595f9"></top-set>
		<tab-top fixed="true" title="预约成功" after="true" color="#ffffff" bgColor="#3595f9" imgSrc="/static/icon/white-back.png"></tab-top>
		<!-- #endif -->
		<view class="order-top"> 
			<view class="title">预约成功</view>
			<view class="text">请您耐心等待，保洁员抢单成功后会在预约时间前30分钟内到达酒店呢...</view>
			<view class="icon"><image src="/static/icon/circle-ok.png" mode=""></image></view>
		</view>
		<view class="main">
			<view class="title">预约详情</view>
			<view class="item">
				房间数量：<view class="text">{{order.count}}间</view>
			</view>
			<view class="item">
				预计费用：<view class="text">￥{{order.price}}</view>
			</view>
			<view class="item">
				服务类型：<view class="text">{{order.name}}</view>
			</view>
			<view class="item">
				预约时间：<view class="text">{{order.dateTime}}</view>
			</view>
			<view class="item">
				房间明细：
			</view>
			<view class="item_num" v-for="(item,index) in order.newOrderArray" :key="index">
				<view class="item_num_title">{{item.storey}}楼</view>
				<view class="room" v-for="(val,key) in item.lists" :key="key">
					<view class="room_item" v-for="(v,i) in val" :key="i">
						{{v.room}}
					</view>
				</view>
			</view>
		</view>
		<view class="btn">
			<view class="subscribe" @tap="subscribe">继续预约</view>
			<view class="examine" @tap="examine(order)">查看订单</view>
		</view>
	</view>
</template>

<script>
	import { mapActions } from 'vuex'
	
	export default {
		data() {
			return {
				order:[]
			}
		},
		onShow(){
			// #ifdef APP-PLUS
				/**
				 * 启动时,状态栏变亮
				 */
			setTimeout(()=>{
				plus.navigator.setStatusBarStyle('light');	 
			},150);
				 
			// #endif
		},
		onUnload(){
			// #ifdef APP-PLUS
				/**
				 * 页面关闭时,状态栏变暗
				 */
				plus.navigator.setStatusBarStyle('dark');
			// #endif
		},
		onLoad(e) {
			this.order = JSON.parse(e.order)
			console.log(this.order);
			let lists = this.order.orderArray1
			//数组去重
			let storeySet = new Set();
			lists.forEach(v=>{
				storeySet.add(v.storey);
			})
			let storey = [...storeySet];
			//数据整理
			let newlists1 = [];
			lists.forEach(v=>{
				storey.forEach((k,i)=>{
					if(v.storey == k){
						newlists1[i]?'':newlists1[i] =[]
						newlists1[i].push(v);
					}
				})
			})
			//数组重组
			let newlists2 = [];
			newlists1.forEach(v=>{
				let result = {};
				result.lists = [];
				for(var i = 0; i < v.length; i += 6){
					result.lists.push(v.slice(i, i + 6));
					result.storey = v[i].storey
				}
				newlists2.push(result)
			})
			//整理数据赋值
			this.order.newOrderArray = newlists2
			console.log(this.order)
		},
		methods: {
			subscribe(){
				uni.navigateTo({
					url: '/pages/hotel/order/order-room'
				});
			},
			examine(e){
				// let order = JSON.stringify(e) 
				this.changeTabIndex('2');
				uni.navigateBack({
					delta: 10
				});
				
			},
			...mapActions({
			  // 在input 的blur 事件中触发回调，并将输入值作为参数返回到store中
					changeTabIndex: 'changeTabIndex' 
			}),
		}
	}
</script>

<style scoped lang="scss">
.order-success{
	width: 750upx;
	.order-top{
		width: 100%;
		box-sizing: border-box;
		height: 188upx;
		position: relative;
		color: #fff;
		padding: 0 64upx;
		background-color: #3595f9;
		.title{
			font-size: 32upx;
			line-height: 76upx;
		}
		.text{
			width: 480upx;
			font-size: 24upx;
			line-height: 36upx;
		}
		.icon{
			position: absolute;
			right: 64upx;
			top: 60upx;
			width: 54upx;
			height: 54upx;
			image{
				width: 100%;
				height: 100%;
				border-radius: 50%;
			}
		}
	}
	.main{
		width: 702upx;
		padding: 30upx 24upx;
		.title{
			font-size: 32upx;
			line-height: 82upx;
		}
		.item{
			font-size: 28upx;
			line-height: 48upx;
			display: flex;
			.text{
				color: #999;
			}
		}
		.item_num{
			width: 702upx;
			.item_num_title{
				font-size: 28upx;
				line-height: 48upx;
				color: #999999;
			}
			.room:nth-child(2){
				border-radius: 0 8upx 0 0;
			}
			.room:nth-last-child(1){
				border-bottom: none;
				border-radius: 0 0 8upx 8upx;
			}
			.room:nth-last-child(1)::after{
				height: 0;
			}
			.room::after{
				position: absolute;
				left: 24upx;
				bottom: 0;
				content: '';
				width: 654upx;
				height: 2upx;
				background: #cde3f9;
			}
			.room{
				display: flex;
				align-items: center;
				justify-content: flex-start;
				height: 70upx;
				position: relative;
				background-color: #7fbcfb;
				.room_item{
					text-align: center;
					font-size: 28upx;
					line-height: 70upx;
					width: 16.666666%;
					color: #ffffff;
				}
			}
		}
	}
	.btn{
		padding: 0 120upx;
		width: 510upx;
		margin:200upx 0 100upx 0;
		display: flex;
		align-items: center;
		text-align: center;
		line-height: 70upx;
		.subscribe{
			width: 240upx;
			height: 70upx;
			border-radius: 8upx;
			border: 1upx solid #3595f9;
			color: #3595f9;
			font-size: 28upx;
			margin-right: 30upx;
		}
		.examine{
			width: 240upx;
			height: 70upx;
			border-radius: 8upx;
			background-color: #3595f9;
			color: #ffffff;
			font-size: 28upx;
		}
	}
}
</style>
